import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vite.dev/config/
export default defineConfig(({ command, mode }) => {
  const env = loadEnv(mode, process.cwd(), '')
  return {
    plugins: [vue()],
    server: {
      host: true,
      port: '5173',
      // open: `http://localhost:5173/#/fifmind/index`,
      cors: true,
      proxy: {
        '/static/fiftest/': {
          target: 'https://test.fifedu.com',
          changeOrigin: true,
          rewrite: (path) => {
            return path
          },
          configure: (proxy, options) => {
            // console.log(proxy)
            // console.log(options)
          }
        },
        '/mock/1213': {
          target: 'http://10.4.87.3:8001',
          changeOrigin: true,
          rewrite: (path) => {
            return path.replace('/mock/1213', '/adapt-web')
          },
          configure: (proxy, options) => {
            // console.log(proxy)
            // console.log(options)
          }
        },
        '^/(graph-manager-web)/.*': {
          target: 'https://graphcs.fifedu.com',
          // target: 'http://10.4.86.35:8001', // 后端本地主机
          changeOrigin: true,
          headers: {
            Cookie: env.VITE_COOKIE || ''
          },
          rewrite: (path) => {
            return path
          }
        }
      }
    }
  }
})
